home *** CD-ROM | disk | FTP | other *** search
- Path: news.ios.com!news
- From: vlad@gramercy.ios.com (vlad)
- Newsgroups: comp.lang.c++
- Subject: Re: Reading derived-class objects in from a file -- possible?
- Date: Thu, 04 Jan 1996 06:02:30 GMT
- Organization: Internet Online Services
- Message-ID: <4cfq2r$4ae@news.ios.com>
- References: <4ceho4$re6@lace.colorado.edu>
- NNTP-Posting-Host: ppp-29.ts-7.hck.idt.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- Robert Dodier <dodier@colorado.edu> wrote:
-
- >Hello,
-
- >I have a simple question but I can't seem to find a simple answer. :)
-
- >I have an abstract class, let's call it class A, and two derived classes
- >B and C. I would *like* to do something like this (never mind that, as
- >stated below, it can't work).
-
- > A* p_something = new A;
- > cin >> *p_something;
- > p_something->do_whatever();
-
- >Within the program, I don't really care if someone gives a B or a C as
- >input -- I'll use the virtual functions of A for access anyway.
-
- >I don't want to have to write:
-
- > cin >> ident;
- > switch ( ident ) {
- > case 'B': p_something = new B; break;
- > case 'C': p_something = new C; break;
- > }
- > cin >> *p_something;
-
-
- If you use Windows or an opertaing system allowing DLLs, then the
- solution is simple.
- Do you use such a OS?
-
- Vlastimil Adamovsky
-
-